<?php
/******************************
 * EQdkp
 * Copyright 2002-2003
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * viewitem.php
 * Began: Fri December 20 2002
 *
 *
 ******************************/

define('EQDKP_INC', true);
$eqdkp_root_path = './';
include_once($eqdkp_root_path . 'common.php');

$user->check_auth('u_item_view');

if ( (isset($_GET[URI_ITEM])) && (intval($_GET[URI_ITEM] > 0)) )
{
    $sql = 'SELECT i.item_id, i.item_name, i.item_value, i.item_date, i.raid_id, i.item_buyer, r.raid_name
            FROM ' . ITEMS_TABLE . ' i, ' . RAIDS_TABLE . " r
            WHERE (r.raid_id = i.raid_id) AND (i.item_name='".addslashes($item_name)."')
            ORDER BY ".$current_order['sql'];

    $sql = 'SELECT item_data_id, item_name, item_jobs, item_level, dropped_from,
                   data_row_one, data_row_two, data_row_three, data_row_four, data_row_five
            FROM ' . ITEM_DATA_TABLE ."
            WHERE item_data_id = '".$_GET[URI_ITEM]."'";

    if ( !($items_result = $db->query($sql)) )
    {
        message_die('Could not obtain item information', '', __FILE__, __LINE__, $sql);
    }
    $item = $db->fetch_record($items_result);

    if ($item['item_name'] == "")
    {
        message_die('Cound not obtain item information', '', __FILE__, __LINE__, $sql);
    }

    if ($_GET['iframe'])
    {
        $small_view = true;
    }
    else
    {
        $small_view = false;
    }
    
    $tpl->assign_vars(array(
        'S_SMALL_VIEW' => $small_view,
        'L_ITEM_NAME' => stripslashes($item['item_name']),
        'L_DROPPED_FROM' => $user->lang['dropped_from'],
        'L_CLASS' => $user->lang['class'],
        'L_LEVEL' => $user->lang['level'],
        'ITEM_DROPPED_FROM' => $item['dropped_from'],
        'ITEM_LEVEL' => $item['item_level'],
        'ITEM_DATA_ROW_ONE' => $item['data_row_one'],
        'ITEM_DATA_ROW_TWO' => $item['data_row_two'],
        'ITEM_DATA_ROW_THREE' => $item['data_row_three'],
        'ITEM_DATA_ROW_FOUR' => $item['data_row_four'],
        'ITEM_DATA_ROW_FIVE' => $item['data_row_five'],
        'ITEM_CLASS' => $item['item_jobs'])
    );

    $pm->do_hooks('/viewitemdata.php');

    $eqdkp->set_vars(array(
        'page_title'    => sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.sprintf($user->lang['viewitem_title'], stripslashes($item_name)),
        'template_file' => 'viewitemdata.html',
        'display'       => true)
    );
}
// No item or no valid item
else
{
    message_die($user->lang['error_invalid_item_provided']);
}
?>
